/*
 * @Date: 2022-04-13 11:25:37
 * @LastEditors: wuyuxin
 * @LastEditTime: 2022-04-16 11:41:26
 * @FilePath: \Vue3-ts-cms\src\service\index.ts
 * @description: 文件描述
 */
import YXRequest from './request'
import { BASE_URL, TIME_OUT } from './request/config'
import { YXRequestConfig } from './request/type'
import localCache from '@/utils/cache'

const yxRequest = new YXRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptor: (config: YXRequestConfig) => {
      // 携带token的拦截
      const token = localCache.getCache('token')
      if (token) {
        config.headers.Authorization = `Bearer ${token}`
      }
      return config
    },
    requestCatchInterceptor: (error) => {
      return error
    },
    responseInterceptor: (res) => {
      return res
    },
    responseCatchInterceptor: (error) => {
      return error
    }
  }
})

export default yxRequest
